<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam - Plugin															/
/	Created by:		broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Support:		http://broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcasteb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0004																	/
/																							/
/========================================== JooSam ========================================*/
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
jimport('joomla.methods');

// JooSam Plugin class
class plgSystemJooSam extends JPlugin{

	public function onAfterDispatch(){
		$app = JFactory::getApplication();
		$adminpage = $app->isAdmin();
		if(!$adminpage){
			$jsm_script = JURI::root().'plugins/system/joosam/scripts/joosam/global.js';
			$jsm_css = JURI::root().'plugins/system/joosam/theme/css/main.css';
			$doc = JFactory::getDocument();
			$doc->addStyleSheet($jsm_css);
			$doc->addScript($jsm_script);
			$doc->addScriptDeclaration($this->createScript());
		}
	}

	protected function createScript(){
		$url = JRoute::_('?option=com_joosam&view=xmldata&loader=dataload&format=raw');
		$javascript = '	if(window.addEventListener){ window.addEventListener("load", joosam.getData("'.$url.'"), false);}' . "\n";
		$javascript .= '	else{window.attachEvent("onload", joosam.getData("'.$url.'"));}' . "\n";
    	return $javascript;
	}
}